#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Net.Mail;

#endregion

namespace TVC.Modules.Com
{
    public partial class frmTestMail : Form
    {
        DTO.LIST_TASKInfo _info;
        MainForm main;
        public frmTestMail(MainForm frm, DTO.LIST_TASKInfo inf)
        {
            InitializeComponent();
            _info = inf;
            main = frm;
        }

        private void btClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btSend_Click(object sender, EventArgs e)
        {
            string kq = "tavico://TASK?id=" + _info.Code;
            if (txP1.Text != "")
                kq += "&P1=" + txP1.Text;
            if (txP2.Text != "")
                kq += "&P2=" + txP2.Text;
            if (txP3.Text != "")
                kq += "&P3=" + txP3.Text;
            if (txP4.Text != "")
                kq += "&P4=" + txP4.Text;
            if (txP5.Text != "")
                kq += "&P5=" + txP5.Text;
            if (txP6.Text != "")
                kq += "&P6=" + txP6.Text;
            if (txP7.Text != "")
                kq += "&P7=" + txP7.Text;
            if (txP8.Text != "")
                kq += "&P8=" + txP8.Text;
            if (txP9.Text != "")
                kq += "&P9=" + txP9.Text;
            if (txP10.Text != "")
                kq += "&P10=" + txP10.Text;
            string[] cmd = kq.Split('?');
            CmdManager.UserID = main.PODInfo.USER_ID;
            CmdManager.Db = main.DB;
            CmdManager.TempPath = MainForm.ServerPath + "ReportTemplate\\";
            CmdManager.ReptPath = MainForm.ServerPath + "Report\\";
            //CmdManager.AppConnect = MainForm.AppConnectString;
            CmdManager.DocumentDirectory = MainForm.ServerPath + "local_log/";
            // CmdManager.RepConnect
            string value = CmdManager.RunCmd(cmd[0], cmd[1], (obj, etv) =>
            {
                AsyncCompletedEventArgs tmp = etv as AsyncCompletedEventArgs;
                if (tmp != null)
                {
                    if (tmp.Error != null)
                        MessageBox.Show(tmp.Error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, false);
                    else
                    {
                        MessageBox.Show("Send mail Successful!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information, false);
                        this.Close();
                        this.Update();
                    }
                }
            });
            if (value != "") MessageBox.Show(value, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, false);

        }
    }
}